<template>
    <div class="form-block-inner">
        <Form :model="formItem" label-position="top" ref="baseForm">
            <div v-for="(val,index) in dataList" :key="index">
                <div class="title-style">流程节点{{index+1}}-{{ val.node_title }}</div>
                <Row v-for="(item,index2) in val.warningList" :key="index2" :gutter="16">
                    <Col span="24">
                        <Row :gutter="16">
                            <Col span="8">
                                <FormItem class="required" label="预警报警内容:">
                                    <Input v-model="item.yj_content"
                                           placeholder="填写预警报警内容"/>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem class="required" label="类型:">
                                    <Select v-model="item.yj_type">
                                        <Option value="1">预警</Option>
                                        <Option value="2">报警</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label=" " class="col-last-btn">
                                    <Button @click="delAction(val, index2)" class="col-last-btn" type="error"
                                            shape="circle" icon="md-close"></Button>
                                </FormItem>
                            </Col>
                        </Row>
                    </Col>
                    <Col span="8">
                        <FormItem class="required" label="预警报警等级:">
                            <Select v-model="item.yj_deng_ji">
                                <Option value="1">一般</Option>
                                <Option value="2">紧急</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem prop="yj_fang_shi" label="预警报警方式:">
                            <Input placeholder="微信、系统消息" v-model="item.yj_fang_shi"></Input>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem prop="yj_tui_song" label="预警报警推送:">
                            <Input placeholder="经办人、单位(部门)主要领导、分管领导、业务处室负责人" v-model="item.yj_tui_song"></Input>
                        </FormItem>
                    </Col>
                    <Divider class="mt10"/>
                </Row>
                <Row>
                    <Col span="24">
                        <Button type="success" @click="add(val.warningList)">添加</Button>
                    </Col>
                </Row>
            </div>
        </Form>
        <div class="btn-style" v-if="dataList.length >0">
            <common-save-btn :base-info-id="baseInfoId" :form-data="dataList" dbName="GovWarning"
                             param-filter="warningList"></common-save-btn>
        </div>
    </div>
</template>

<script>
import CommonSaveBtn from '@/components/common-save-btn'
import { select } from '@/api/setting'

export default {
  name: 'WarningSetting',
  components: { CommonSaveBtn },
  props: {
    options: {
      type: Array,
      default: () => {
        return []
      }
    },
    tabName: {
      type: String,
      default: () => {
        return ''
      }
    },
    baseInfoId: {
      type: String,
      default: () => {
        return ''
      }
    }
  },
  data () {
    return {
      formItem: {},
      dataList: []
    }
  },
  methods: {
    init () {
      if (this.tabName === '19') {
        let param = { base_info_id: this.baseInfoId }
        select('GovWarning', param).then(res => {
          this.loading = false
          if (res.data.errcode === 0) {
            for (let i = 0; i < this.dataList.length; i++) {
              this.dataList[i].warningList = []
              for (let j = 0; j < res.data.data.length; j++) {
                if (this.dataList[i].id === res.data.data[j].gov_flow_id) {
                  res.data.data[j].base_info_id = this.baseInfoId
                  this.dataList[i].warningList.push(res.data.data[j])
                }
              }
            }
            this.dataList = this.$common.xeUtils.clone(this.dataList)
          } else {
            this.$Message.error('数据获取失败!')
          }
        }).catch(ret => {
          this.loading = false
          this.$Message.error(ret)
        })
      }
    },
    success (val) {
      val = this.$common.xeUtils.isEmpty(val) ? '操作成功' : val
      this.$Message.success(val)
    },
    error (data) {
      this.$Message.error({
        content: '操作失败,\n' + data.errmsg
      })
    },
    add (val) {
      val.push({})
      this.dataList = this.$common.xeUtils.clone(this.dataList)
    },
    delAction (item, index) {
      item.warningList.splice(index, 1)
      this.dataList = this.$common.xeUtils.clone(this.dataList)
    }
  },
  watch: {
    options (data) {
      this.dataList = data
    },
    dataList (data) {
      this.$emit('result', data)
    },
    tabName (data) {
      this.init()
    },
    baseInfoId (data) {
      this.baseInfoId = data
    }
  }
}
</script>

<style scoped>
    .btn-style {
        margin-top: 5px;
    }

    .col-last-btn {
        float: right;
        margin-right: 40px;
    }

    .required /deep/ .ivu-form-item-label:before {
        content: '*';
        display: inline-block;
        margin-right: 4px;
        line-height: 1;
        font-family: SimSun;
        font-size: 14px;
        color: #ed4014;
    }
</style>
